package com.joker.aigc.chat.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joker.aigc.chat.service.UserFriendService;
import com.joker.aigc.domain.dto.UserApplyCriteria;
import com.joker.aigc.domain.dto.UserApplyDto;
import com.joker.aigc.domain.dto.UserFriendDto;
import com.joker.aigc.domain.entity.R;
import com.joker.aigc.domain.vo.UserApplyVo;
import com.joker.aigc.domain.vo.UserVo;
import com.joker.aigc.utils.RequestHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@Slf4j
@RestController
@RequestMapping("/api/1.0/friend")
@Tag(name = "friend", description = "用户 申请好友，查找好友，拉黑好友")
public class FriendController {

    final UserFriendService userFriendService;

    @Operation(description = "查询用户的好友信息")
    @GetMapping
    public R<List<UserVo>> queryUserFriend() {
        Long uid = RequestHolder.get().getUid();
        return R.ok(userFriendService.queryUserFriend(uid));
    }

    @Operation(description = "查询用户的申请列表信息信息")
    @PostMapping("/queryUserApplyInfo")
    public R<Page<UserApplyVo>> queryUserApplyInfo(@RequestBody UserApplyCriteria criteria) {
        Long uid = RequestHolder.get().getUid();
        log.info("用户申请：{}", criteria);
        return R.ok(userFriendService.queryUserApplyInfo(uid, criteria));
    }

    @Operation(description = "申请好友信息")
    @PostMapping("/addUserApply")
    public R<String> addUserApply(@RequestBody UserApplyDto userApplyDto) {
        Long uid = RequestHolder.get().getUid();
        userFriendService.addUserApply(uid, userApplyDto);
        return R.ok("申请好友成功");
    }


    @Operation(description = "通过好友申请")
    @PostMapping("/accessUserApply")
    public R<String> accessApply(@NotNull(message = "申请id不存在") Long id) {
        userFriendService.accessUserApply(id);
        return R.ok("申请好友成功");
    }


    @Operation(description = "拒绝好友申请")
    @PostMapping("/deleteUserApply")
    public R<String> deleteUserApply(Long id) {
        userFriendService.deleteUserApply(id);
        return R.ok("拒绝好友申请成功");
    }


    @Operation(description = "拉黑好友")
    @PutMapping
    public R<String> blackFriend(@RequestBody UserFriendDto userFriendDto) {
        Long uid = RequestHolder.get().getUid();
        userFriendDto.setUid(uid);
        userFriendService.blackFriend(userFriendDto);
        return R.ok("申请好友成功");
    }


}
